package cn.itcast.order.service;


import cn.itcast.feign.clients.UserClient;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.feign.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private UserClient userClient;
//    @Autowired
//    private RestTemplate restTemplate;
    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
    //    String url = "http://localhost:8081/user/";
//        String url = "http://userservice/user/";
//        User user = restTemplate.getForObject(url + order.getUserId(), User.class);

        //2.用Feign远程调用
        User user = userClient.findById(order.getUserId());

        //3.封装User到Order
        order.setUser(user);
        // 4.返回
        return order;
    }
}
